﻿using System.ComponentModel.Composition;
using AppsGenerator.Utils;

namespace AppsGenerator.WebGenerators.WebControllerGenerator
{
    /// <summary>
    /// The class is reponsible for generating partial controller with image
    /// </summary>
    [Export(typeof(PartialControllerImageGenerator))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class PartialControllerImageGenerator : PartialControllerGenerator
    {
        /// <summary>
        /// The constructor with image
        /// </summary>
        public PartialControllerImageGenerator()
        {
            // Start to deserialize xml template file
            this._imgAttr = GlobalVariables.ImageAttr;
            this.XMLTemplate = "PartialControllerWithImageTemplate.xml";
            this.DeserializeTemplate();
            this.UpdateAlgorithm(this._imgAttr);
        }

        /// <summary>
        /// Initialize the algorithms for Delete, Update, Insert Item
        /// </summary>
        /// <param name="img"></param>
        private void UpdateAlgorithm(string img)
        {
            GlobalVariables.ImageAttr = img;
            this._deleteAlgorithm = IoC.Get<DeleteControllerItemByImageAlgorithm>();
            this._updateAlgorithm = IoC.Get<UpdateControllerItemByImageAlgorithm>();
            this._insertAlgorithm = IoC.Get<InsertControllerItemByImageAlgorithm>();
        }
    }
}
